package com.labichaoka.chaoka.ui.home.fragment.my.feedback;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.labichaoka.chaoka.R;
import com.labichaoka.chaoka.base.BaseActivity;
import com.labichaoka.chaoka.entity.FeedBackRequest;
import com.labichaoka.chaoka.utils.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class FeedBackActivity extends BaseActivity implements FeedBackView{
    @BindView(R.id.txt_bottom)
    TextView txtBottom;
    @BindView(R.id.edit)
    TextView edit;
    @BindView(R.id.commit)
    Button commit;
    private String editStr;

    private FeedBackPresenter presenter;

    @Override
    protected int initLayoutId() {
        return R.layout.activity_feed_back;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        presenter=new FeedBackPresenterImpl(new FeedBackInteractorImpl(),this);

        edit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                editStr=s.toString().trim();
                int count=editStr.length();
                txtBottom.setText(count+"/300字");
                if (count<10){
                    commit.setEnabled(false);
                }else{
                    commit.setEnabled(true);
                }
            }
        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @OnClick(R.id.commit)
    public void click(View v){
        FeedBackRequest request=new FeedBackRequest();
        request.setChannelSource("蜡笔超卡");
        request.setFileType("10200");
        request.setImagePath("");
        request.setProblems(editStr);
        presenter.commitFeedBack(request);
    }

    @Override
    public void showProgress() {
        showLoadingProgress();
    }

    @Override
    public void hideProgress() {
        hideLoadingProgress();
    }

    @Override
    public void showMessage(String str) {
        ToastUtils.show(str);
    }

    @Override
    public void commitSuccess() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onDestroy();
    }
}
